---
title:  Creating a Region Through the API
---

<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

You can use the Geode caching API to create regions in your cache after startup. For run-time region creation, you need to use the API.

Before you start, configure your `Cache` or `ClientCache` and determine the region shortcut and other attributes settings your region needs.

Region creation is subject to attribute consistency checks, both internal to the cache and, if the region is not local, between all caches where the region is defined. The requirements for consistency between region attributes are detailed in the online Java API documentation.

1.  

    Use a region shortcut to create your region factory. 
    -   

        In peers and servers, use `org.apache.geode.cache.RegionFactory`.
    -   

        In clients, use `org.apache.geode.cache.client.ClientRegionFactory`.

2.  

    (Optional) Use the region factory to further configure your region. 
3.  

    Create your region from the configured region factory. 

When you run your member with the region creation code, the region will be created in the cache.

## Examples

Creating a partitioned region using RegionFactory:

``` pre
RegionFactory rf =   
    cache.createRegionFactory(RegionShortcut.PARTITION);
rf.addCacheListener(new LoggingCacheListener());
custRegion = rf.create("customer");
```

Creating a modified partitioned region using RegionFactory:

``` pre
PartitionAttributesFactory paf = new PartitionAttributesFactory<CustomerId, String>();
paf.setPartitionResolver(new CustomerOrderResolver());

RegionFactory rf = 
    cache.createRegionFactory(RegionShortcut.PARTITION);
rf.setPartitionAttributes(paf.create());
rf.addCacheListener(new LoggingCacheListener());
custRegion = rf.create("customer");
```

Creating a client region with a pool specification using ClientRegionFactory:

``` pre
ClientRegionFactory<String,String> cRegionFactory = 
    cache.createClientRegionFactory(PROXY);
Region<String, String> region = 
    cRegionFactory.setPoolName("Pool3").create("DATA");
```


